package cn.ibizlab.odoo.core.odoo_stock.service.impl;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
import java.math.BigInteger;
import java.util.Collection;

import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cglib.beans.BeanCopier;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import cn.ibizlab.odoo.core.client.model.Istock_package_level;
import cn.ibizlab.odoo.core.odoo_stock.domain.Stock_package_level;
import cn.ibizlab.odoo.core.odoo_stock.filter.Stock_package_levelSearchContext;
import cn.ibizlab.odoo.core.odoo_stock.service.IStock_package_levelService;
import cn.ibizlab.odoo.util.SearchResult;
import cn.ibizlab.odoo.util.log.IBIZLog;

/**
 * 实体[库存包装层级] 服务对象接口实现
 */
@Slf4j
@IBIZLog
@Service
public class Stock_package_levelServiceImpl implements IStock_package_levelService {

    @Autowired
    private cn.ibizlab.odoo.core.client.service.Istock_package_levelClientService stock_package_levelClientService;

    @Override
    public void removeBatch(Collection<? extends Serializable> idList, int batchSize) {

        //stock_package_levelClientService.removeBatch(stock_package_levels) ;

    }

    @Override
    public boolean remove(Integer id) {
        boolean bOk = false ;
        Istock_package_level clientModel = stock_package_levelClientService.createModel();
        clientModel.setId(id);
        stock_package_levelClientService.remove(clientModel) ;
        bOk = true ;
        return bOk ;
    }

    @Override
    public void updateBatch(List<Stock_package_level> stock_package_levels, int batchSize) {

        //stock_package_levelClientService.updateBatch(stock_package_levels,batchSize) ;

    }

    @Override
    public Stock_package_level get(Integer id) {
        Istock_package_level clientModel = stock_package_levelClientService.createModel();
        clientModel.setId(id);
        stock_package_levelClientService.get(clientModel) ;
        return this.convert2Domain(clientModel,null);
    }

    @Override
    public Stock_package_level get(Stock_package_level stock_package_level) {
        Stock_package_level retstock_package_level = this.get(stock_package_level.getId()) ;
    	BeanCopier copier=BeanCopier.create(retstock_package_level.getClass(), stock_package_level.getClass(), false);
        copier.copy(retstock_package_level, stock_package_level, null);
        return stock_package_level ;
    }

    @Override
    public boolean create(Stock_package_level stock_package_level) {
        boolean bOk = false ;
        Istock_package_level clientModel = this.convert2Model(stock_package_level,null);
        stock_package_levelClientService.create(clientModel) ;
        this.convert2Domain(clientModel,stock_package_level);
        bOk = true ;

        return bOk ;
    }

    @Override
    public void createBatch(List<Stock_package_level> stock_package_levels, int batchSize) {

                        //stock_package_levelClientService.createBatch(stock_package_levels,batchSize) ;

    }

    @Override
    public boolean update(Stock_package_level stock_package_level) {
        boolean bOk = false ;
        Istock_package_level clientModel = this.convert2Model(stock_package_level,null);
        stock_package_levelClientService.update(clientModel) ;
        this.convert2Domain(clientModel,stock_package_level) ;
        bOk = true;
        return bOk ;
    }

    /**
     * 查询集合 默认查询
     */
    @Override
    public Page<Stock_package_level> searchDefault(Stock_package_levelSearchContext context) {
        List<Stock_package_level> list = new ArrayList<Stock_package_level>();
        Page<cn.ibizlab.odoo.core.client.model.Istock_package_level> clientModelList = stock_package_levelClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Istock_package_level clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Stock_package_level>(list, context.getPageable(), clientModelList.getTotalElements());
    }


    /**
     * 根据用户查询
     */
    @Override
    public Page<Stock_package_level> selectByOdoo_create(Integer id){
        Stock_package_levelSearchContext context = new Stock_package_levelSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Stock_package_level> list = new ArrayList<Stock_package_level>();
        Page<cn.ibizlab.odoo.core.client.model.Istock_package_level> clientModelList = stock_package_levelClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Istock_package_level clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Stock_package_level>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据用户查询
     */
    @Override
    public Page<Stock_package_level> selectByOdoo_write(Integer id){
        Stock_package_levelSearchContext context = new Stock_package_levelSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Stock_package_level> list = new ArrayList<Stock_package_level>();
        Page<cn.ibizlab.odoo.core.client.model.Istock_package_level> clientModelList = stock_package_levelClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Istock_package_level clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Stock_package_level>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据库存位置查询
     */
    @Override
    public Page<Stock_package_level> selectByOdoo_location_dest(Integer id){
        Stock_package_levelSearchContext context = new Stock_package_levelSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Stock_package_level> list = new ArrayList<Stock_package_level>();
        Page<cn.ibizlab.odoo.core.client.model.Istock_package_level> clientModelList = stock_package_levelClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Istock_package_level clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Stock_package_level>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据调拨查询
     */
    @Override
    public Page<Stock_package_level> selectByOdoo_picking(Integer id){
        Stock_package_levelSearchContext context = new Stock_package_levelSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Stock_package_level> list = new ArrayList<Stock_package_level>();
        Page<cn.ibizlab.odoo.core.client.model.Istock_package_level> clientModelList = stock_package_levelClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Istock_package_level clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Stock_package_level>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据包裹查询
     */
    @Override
    public Page<Stock_package_level> selectByOdoo_package(Integer id){
        Stock_package_levelSearchContext context = new Stock_package_levelSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Stock_package_level> list = new ArrayList<Stock_package_level>();
        Page<cn.ibizlab.odoo.core.client.model.Istock_package_level> clientModelList = stock_package_levelClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Istock_package_level clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Stock_package_level>(list, context.getPageable(), clientModelList.getTotalElements());

    }



    public Istock_package_level convert2Model(Stock_package_level domain , Istock_package_level model) {
        if(domain == null)
            return model ;
        if(model==null){
            model = stock_package_levelClientService.createModel() ;
        }

         if(domain.getMove_line_idsDirtyFlag())
            model.setMove_line_ids(domain.getMove_line_ids());
         if(domain.getMove_idsDirtyFlag())
            model.setMove_ids(domain.getMove_ids());
         if(domain.getCreate_dateDirtyFlag())
            model.setCreate_date(domain.getCreate_date());
         if(domain.getLocation_idDirtyFlag())
            model.setLocation_id(domain.getLocation_id());
         if(domain.getShow_lots_textDirtyFlag())
            model.setShow_lots_text(domain.getShow_lots_text());
         if(domain.get__last_updateDirtyFlag())
            model.set__last_update(domain.get__last_update());
         if(domain.getIs_doneDirtyFlag())
            model.setIs_done(domain.getIs_done());
         if(domain.getShow_lots_m2oDirtyFlag())
            model.setShow_lots_m2o(domain.getShow_lots_m2o());
         if(domain.getStateDirtyFlag())
            model.setState(domain.getState());
         if(domain.getIdDirtyFlag())
            model.setId(domain.getId());
         if(domain.getWrite_dateDirtyFlag())
            model.setWrite_date(domain.getWrite_date());
         if(domain.getIs_fresh_packageDirtyFlag())
            model.setIs_fresh_package(domain.getIs_fresh_package());
         if(domain.getDisplay_nameDirtyFlag())
            model.setDisplay_name(domain.getDisplay_name());
         if(domain.getPicking_id_textDirtyFlag())
            model.setPicking_id_text(domain.getPicking_id_text());
         if(domain.getWrite_uid_textDirtyFlag())
            model.setWrite_uid_text(domain.getWrite_uid_text());
         if(domain.getPackage_id_textDirtyFlag())
            model.setPackage_id_text(domain.getPackage_id_text());
         if(domain.getLocation_dest_id_textDirtyFlag())
            model.setLocation_dest_id_text(domain.getLocation_dest_id_text());
         if(domain.getCreate_uid_textDirtyFlag())
            model.setCreate_uid_text(domain.getCreate_uid_text());
         if(domain.getPicking_source_locationDirtyFlag())
            model.setPicking_source_location(domain.getPicking_source_location());
         if(domain.getWrite_uidDirtyFlag())
            model.setWrite_uid(domain.getWrite_uid());
         if(domain.getPicking_idDirtyFlag())
            model.setPicking_id(domain.getPicking_id());
         if(domain.getPackage_idDirtyFlag())
            model.setPackage_id(domain.getPackage_id());
         if(domain.getCreate_uidDirtyFlag())
            model.setCreate_uid(domain.getCreate_uid());
         if(domain.getLocation_dest_idDirtyFlag())
            model.setLocation_dest_id(domain.getLocation_dest_id());
        return model ;
    }

    public Stock_package_level convert2Domain( Istock_package_level model ,Stock_package_level domain) {
        if(model == null)
            return domain ;
        if(domain == null){
            domain = new Stock_package_level();
        }

        if(model.getMove_line_idsDirtyFlag())
            domain.setMove_line_ids(model.getMove_line_ids());
        if(model.getMove_idsDirtyFlag())
            domain.setMove_ids(model.getMove_ids());
        if(model.getCreate_dateDirtyFlag())
            domain.setCreate_date(model.getCreate_date());
        if(model.getLocation_idDirtyFlag())
            domain.setLocation_id(model.getLocation_id());
        if(model.getShow_lots_textDirtyFlag())
            domain.setShow_lots_text(model.getShow_lots_text());
        if(model.get__last_updateDirtyFlag())
            domain.set__last_update(model.get__last_update());
        if(model.getIs_doneDirtyFlag())
            domain.setIs_done(model.getIs_done());
        if(model.getShow_lots_m2oDirtyFlag())
            domain.setShow_lots_m2o(model.getShow_lots_m2o());
        if(model.getStateDirtyFlag())
            domain.setState(model.getState());
        if(model.getIdDirtyFlag())
            domain.setId(model.getId());
        if(model.getWrite_dateDirtyFlag())
            domain.setWrite_date(model.getWrite_date());
        if(model.getIs_fresh_packageDirtyFlag())
            domain.setIs_fresh_package(model.getIs_fresh_package());
        if(model.getDisplay_nameDirtyFlag())
            domain.setDisplay_name(model.getDisplay_name());
        if(model.getPicking_id_textDirtyFlag())
            domain.setPicking_id_text(model.getPicking_id_text());
        if(model.getWrite_uid_textDirtyFlag())
            domain.setWrite_uid_text(model.getWrite_uid_text());
        if(model.getPackage_id_textDirtyFlag())
            domain.setPackage_id_text(model.getPackage_id_text());
        if(model.getLocation_dest_id_textDirtyFlag())
            domain.setLocation_dest_id_text(model.getLocation_dest_id_text());
        if(model.getCreate_uid_textDirtyFlag())
            domain.setCreate_uid_text(model.getCreate_uid_text());
        if(model.getPicking_source_locationDirtyFlag())
            domain.setPicking_source_location(model.getPicking_source_location());
        if(model.getWrite_uidDirtyFlag())
            domain.setWrite_uid(model.getWrite_uid());
        if(model.getPicking_idDirtyFlag())
            domain.setPicking_id(model.getPicking_id());
        if(model.getPackage_idDirtyFlag())
            domain.setPackage_id(model.getPackage_id());
        if(model.getCreate_uidDirtyFlag())
            domain.setCreate_uid(model.getCreate_uid());
        if(model.getLocation_dest_idDirtyFlag())
            domain.setLocation_dest_id(model.getLocation_dest_id());
        return domain ;
    }


}
